/*
 * LoggerableManager.h
 *
 *  Created on: 2009/01/31
 *      Author: Yongshik Cho
 */

#ifndef LOGGERABLEMANAGER_H_
#define LOGGERABLEMANAGER_H_

#include <vector>

#include "core/ISingleton.h"

#ifndef LOGGERABLE_H_
#	include "active/Loggerable.h"
#endif

#include "sqplus/sqplus.h"
using namespace SqPlus;


class LoggerableManager: public ISingleton<LoggerableManager>
{
public:
	LoggerableManager();
	virtual ~LoggerableManager();

public:
	static LoggerableManager& GetInstance()
	{
		assert(m_pInstance);
		return *m_pInstance;
	}
	static LoggerableManager* GetInstancePtr()
	{
		return m_pInstance;
	}

public:
	void add(Loggerable*);
	void sub(Loggerable*);
	Loggerable* get(const String& path);
	Loggerable* get(uint32 index = 0);
	inline void print(const String& str) 
	{ 
		Loggerable* log = get();
		if(log)
		{
			log->printTimeStamp(); 
			(*log) << str << std::endl;
		}
	}

private:
	const bool isExists(Loggerable* log);

private:
	vector<Loggerable*>		mLoggerables;
};

//must be declared here
DECLARE_INSTANCE_TYPE(LoggerableManager)

#ifndef AltoLog
#	define AltoLog(content) { Loggerable* log = LoggerableManager::GetInstance().get(); if(log) { log->printTimeStamp(); (*log) << content << std::endl; } }
#endif

#endif /* LOGGERABLEMANAGER_H_ */
